package com.longway.common.db.id;

import com.jfinal.plugin.activerecord.Db;

public class OracleSeqValueFactory implements IIdFactory{
	
	private static final OracleSeqValueFactory me = new OracleSeqValueFactory();
	
	private String seqName = "";
	
	public static OracleSeqValueFactory me(String seqName) {
		me.seqName = seqName + ".nextval";
		return me;
	}

	@Override
	public Object getId() {
		if(seqName.equals("")){
			throw new IllegalArgumentException("oracle seqName can not be null.");
		}
		String sql = "select "+seqName+" as seq from dual";
		return Db.findFirst(sql).getLong("seq");
	}
}
